# -----------------------------------------------
# Author: yuz
# Copyright: 湖南零檬信息技术有限公司
# Email: wagyu2016@163.com
# Phone&Wechat: 18173179913
# Site: http://www.lemonban.com
# Forum: http://testingpai.com
# -----------------------------------------------
# pip install pymysql

import pymysql

# 连接数据库
from pymysql.cursors import DictCursor

conn = pymysql.connect(host='47.113.180.81',
                port=3306,
                user='lemon',
                password='lemon123',
                database='yami_shops',
                cursorclass=DictCursor)
print(conn)


# 创建一个游标对象
cursor = conn.cursor()

# 执行 sql 语句
# 查询 yami_shops 数据库， 表名tz_sms_log
# user_phone = 18711277355, 得到 mobile_code
sql = "SELECT mobile_code,id,user_id FROM tz_sms_log WHERE user_phone = '18711277355' LIMIT 5;"
cursor.execute(sql)

# 得到所有的数据
records = cursor.fetchall()
print(records)


# 关闭游标，关闭连接
cursor.close()
conn.close()





